/**
 * https://leetcode-cn.com/problems/longest-continuous-increasing-subsequence/
 * 最长连续递增序列 需要连续递增的才算
 * @param nums 
 */
const findLengthOfLCIS = (nums: number[]): number => {
    // [1,3,5,4,7]

    const len = nums.length;

    // 表示连续的长度数
    let length = 1,
        max = 1;

    for (let i = 1; i < len; i++) {
        if (nums[i] > nums[i - 1]) {
            // 连续长度数+1
            length++
        } else {
            // 连续长度数恢复为1
            length = 1;
        }
        max = Math.max(length, max)
    }
    return max;
};

console.log(findLengthOfLCIS([1, 3, 5, 4, 7]))

// 动态规划
const findLengthOfLCIS2 = (nums: number[]): number => {
    // [1,3,5,4,7]

    const len = nums.length;

    // dp[i] 表示以i为底的最长连续递增序列长度

    // 状态转移方程
    // if (nums[i] > nums[i - 1]) dp[i] = dp[i - 1] + 1
    // else dp[i] = 1

    const dp: number[] = new Array(len).fill(1)

    let max = 1;

    for (let i = 1; i < len; i++) {
        if (nums[i] > nums[i - 1]) {
            dp[i] = dp[i - 1] + 1
            max = Math.max(dp[i], max)
        }
    }
    return max;
};